home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagg_m.zip / HARDWARE.SWG / 0034_CMOS reading.pas < prev    next >
Pascal/Delphi Source File  |  1994-08-25  |  3KB  |  97 lines

  1. {
  2. From: landen@cir.frg.eur.nl (Peter van der Landen)
  3.  
  4. >I am attempting to write a program in TP6.0 that reads the CMOS memory
  5. >(IBM PC) and saves the settings to a disk file.  I know there are 255
  6. >locations, but I don't know where.  If someone could point me to the
  7. >correct memory addresses, I'd really appreciate it.  Thanks (in advance)!
  8.  
  9. This unit (by an unknown other) shows you how it's done. The CMOS memory is
  10. not part of the PC's main memory. Values are written/read by accessing an
  11. I/O port.
  12.  
  13. }
  14. unit CMOS;
  15.  
  16. Interface
  17.  
  18. const
  19.      ClockSec  = $00;    { RTclock seconds }
  20.      ClockMin  = $02;    { RTclock minutes }
  21.      ClockHour = $04;    { RTclock hours }
  22.      ClockDOW  = $06;    { RTclock day of week }
  23.      ClockDay  = $07;    { RTclock day in month }
  24.      ClockMon  = $08;    { RTclock month }
  25.      ClockYear = $09;    { RTclock year (mod 100)}
  26.      AlarmSec  = $01;    { Alarm seconds }
  27.      AlarmMin  = $03;    { Alarm minutes }
  28.      AlarmHour = $05;    { Alarm hours }
  29.      Diskettes = $10;    { Floppy disk type byte }
  30.      HardDisk  = $12;    { Regular hard disk type }
  31.      HDExt1    = $19;    { Extended hard disk type, unit 1 }
  32.      HDExt2    = $1A;    { Extended hard disk type, unit 2 }
  33.      Equipment = $14;    { Equipment list }
  34.      CheckLo   = $2F;    { Checksum low }
  35.      CheckHi   = $2E;    { Checksum high }
  36.      BaseLo    = $15;    { Base mem low }
  37.      BaseHi    = $16;    { Base mem high }
  38.      ExpdLo    = $17;    { Expansion mem size low }
  39.      ExpdHi    = $18;    { Expansion mem size high }
  40.      StatRegA  = $0A;    { Status Register A }
  41.      StatRegB  = $0B;    { Status register B }
  42.      StatRegC  = $0C;    { Status register C }
  43.      StatRegD  = $0D;    { Status register D }
  44.      DiagStat  = $0E;    { Diagnostic status byte }
  45.      ShutDown  = $0F;    { Shutdown status byte }
  46.      Century   = $32;    { BCD Century number }
  47.      AltExpdLo = $30;    { Expansion mem size low (alternate) }
  48.      AltExpdHi = $31;    { Expansion mem size high (alternate) }
  49.      InfoFlags = $33;    { Bit 7 set = top 128k installed, bit
  50.                            6 set = first user message (?) }
  51.  
  52. function ReadCmos(Address: byte): byte;
  53.           { Returns the byte at the given CMOS ADDRESS }
  54.  
  55. procedure WriteCmos(Address, Data: byte);
  56.           { Writes DATA to ADDRESS in CMOS ram }
  57.  
  58. procedure SetCMOSCheckSum;
  59.           { Sets the CMOS checksum after you've messed with it :-}
  60.  
  61. { The following bytes are RESERVED: $11, $13, $1B-$2D, and
  62.   $34-$3F ($3F marks the end of the CMOS area).  You'll note that
  63.   some of these are included in the checksum calculation. }
  64.  
  65. implementation
  66.  
  67. const
  68.      CmosAddr  = $70;    { CMOS control port }
  69.      CmosData  = $71;    { CMOS data port }
  70.  
  71. function ReadCmos(Address: byte): byte;
  72. begin
  73.      port[CmosAddr] := Address;
  74.      ReadCmos := port[CmosData]
  75. end; {ReadCmos}
  76.  
  77. procedure WriteCmos(Address, Data: byte);
  78. begin
  79.      port[CmosAddr] := Address;
  80.      port[CmosData] := Data
  81. yend; {WriteCmos}
  82.  
  83. procedure SetCMOSCheckSum;
  84. { The checksum is simply the sum of $10 to $2D 
  85.   (some of these bytes are reserved) }
  86.  
  87. var
  88.      I, Sum: word;
  89. begin
  90.      Sum := 0;
  91.      for I:= $10 to $2D do Sum := Sum + ReadCmos(I);
  92.      WriteCmos(CheckHi, Hi(sum));
  93.      WriteCmos(CheckLo, Lo(sum));
  94. end; {SetCMOSCheckSum}
  95.  
  96. end.
  97.